Ext.define('DCApp.view.GridFilterPlugin', {
	extend: 'Ext.plugin.Abstract',
	alias: 'plugin.gfplugin',
	constructor: function(config) {
		var me = this;
		Ext.apply(me, config);
	},
	init: function(cmp) {
		 this.cmp = cmp;
		 var me=this;
		 me.combo = me.getColumnMenu(cmp);
		 me.comoper = me.getOperCombo();
		 var tbar = this.cmp.down('toolbar');
		 tbar.insert(0,[me.combo,me.comoper,{
		 	text:'检索'
		 	}]);
        // this.cmp.on('render', this.onRender, this);
		var its=[];
		for(var i=0; i<5; i++){
			its.push({
	        	active:true,
	        	closable:true,
    			text:'检索条件'+i
    			});
		}
		cmp.addDocked([{
			style:'background-color:white',
	        xtype: 'tabbar',
	        dock: 'top',
	        id:'tbar_tags',
	        activeItem:1,
	        items: its
	    }])[0].items;
    },
    getOperCombo: function(cmp){
		return Ext.create('Ext.form.field.ComboBox', {
			store: new Ext.data.SimpleStore({
				fields: ['text', 'value'],
				data: [['等于','eq'],['包含','like'],['范围','between']]
			}),
			mode: 'local',
			displayField: 'text',
			valueField: 'value',
			allowBlank: true,
			triggerAction: 'all',
			emptyText : '比较',
			value:'like',
			width: 70,
			enableKeyEvents: true
		});    	
    },
	getColumnMenu: function(cmp) {
		var me = this;
		var its=[];
		var columns = cmp.columnManager.getColumns();
		for(var i=0; i<columns.length; i++){
			var col = columns[i];
			var filter = col.filter;
			if(!filter)
				continue;
			filter.createMenu();
			its.push({text:col.text,
				checked:false,
				menu:col.filter.menu
			});
		}
		return {
			xtype:'splitbutton',
            text:'检索',
            iconCls: null,
            menu:its
        };
	},

	getColumnCombo: function(cmp) {
		var me = this;
		var cols=[];
		var columns = cmp.columnManager.getColumns();
		for(var i=0; i<cmp.columns.length; i++){
			var col = cmp.columns[i];
			cols.push([col.text,col.dataIndex]);
		}
		return Ext.create('Ext.form.field.ComboBox', {
			store: new Ext.data.SimpleStore({
				fields: ['text', 'value'],
				data: cols
			}),
			mode: 'local',
			displayField: 'text',
			valueField: 'value',
			allowBlank: true,
			triggerAction: 'all',
			emptyText : '请选择属性',
			enableKeyEvents: true
		});
	},
	onRender: function(combo) {
		var me=this;
				 
	},
	destory: function() {
		var me = this;
		me.combo.clearListeners();
		Ext.destroy(me.combo);
		delete me.combo;
	}
});